﻿
#region Using directives

using System;
using System.Collections;
using System.Collections.Specialized;


using System.Web.Configuration;
using System.Data;
using System.Data.Common;
using System.Configuration.Provider;

using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

using mepostras.BLL;
using mepostras.DAL;
using mepostras.DAL.Bases;

#endregion

namespace mepostras.DAL.SqlClient
{
	/// <summary>
	/// This class is the Sql implementation of the NetTiersProvider.
	/// </summary>
	public sealed class SqlNetTiersProvider : mepostras.DAL.Bases.NetTiersProvider
	{
		private static object syncRoot = new Object();
		private string _applicationName;
        private string _connectionString;
        private bool _useStoredProcedure;
        string _providerInvariantName;
		
		/// <summary>
		/// Initializes a new instance of the <see cref="SqlNetTiersProvider"/> class.
		///</summary>
		public SqlNetTiersProvider()
		{	
		}		
		
		/// <summary>
        /// Initializes the provider.
        /// </summary>
        /// <param name="name">The friendly name of the provider.</param>
        /// <param name="config">A collection of the name/value pairs representing the provider-specific attributes specified in the configuration for this provider.</param>
        /// <exception cref="T:System.ArgumentNullException">The name of the provider is null.</exception>
        /// <exception cref="T:System.InvalidOperationException">An attempt is made to call <see cref="M:System.Configuration.Provider.ProviderBase.Initialize(System.String,System.Collections.Specialized.NameValueCollection)"></see> on a provider after the provider has already been initialized.</exception>
        /// <exception cref="T:System.ArgumentException">The name of the provider has a length of zero.</exception>
		public override void Initialize(string name, NameValueCollection config)
        {
            // Verify that config isn't null
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            // Assign the provider a default name if it doesn't have one
            if (String.IsNullOrEmpty(name))
            {
                name = "SqlNetTiersProvider";
            }

            // Add a default "description" attribute to config if the
            // attribute doesn't exist or is empty
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", "NetTiers Sql provider");
            }

            // Call the base class's Initialize method
            base.Initialize(name, config);

            // Initialize _applicationName
            _applicationName = config["applicationName"];

            if (string.IsNullOrEmpty(_applicationName))
            {
                _applicationName = "/";
            }
            config.Remove("applicationName");


            #region "Initialize UseStoredProcedure"
            string storedProcedure  = config["useStoredProcedure"];
           	if (string.IsNullOrEmpty(storedProcedure))
            {
                throw new ProviderException("Empty or missing useStoredProcedure");
            }
            this._useStoredProcedure = Convert.ToBoolean(config["useStoredProcedure"]);
            config.Remove("useStoredProcedure");
            #endregion

			#region ConnectionString

			// Initialize _connectionString
			_connectionString = config["connectionString"];
			config.Remove("connectionString");

			string connect = config["connectionStringName"];
			config.Remove("connectionStringName");

			if ( String.IsNullOrEmpty(_connectionString) )
			{
				if ( String.IsNullOrEmpty(connect) )
				{
					throw new ProviderException("Empty or missing connectionStringName");
				}

				if ( DataRepository.ConnectionStrings[connect] == null )
				{
					throw new ProviderException("Missing connection string");
				}

				_connectionString = DataRepository.ConnectionStrings[connect].ConnectionString;
			}

            if ( String.IsNullOrEmpty(_connectionString) )
            {
                throw new ProviderException("Empty connection string");
			}

			#endregion
            
             #region "_providerInvariantName"

            // initialize _providerInvariantName
            this._providerInvariantName = config["providerInvariantName"];

            if (String.IsNullOrEmpty(_providerInvariantName))
            {
                throw new ProviderException("Empty or missing providerInvariantName");
            }
            config.Remove("providerInvariantName");

            #endregion

        }
		
		/// <summary>
		/// Creates a new <see cref="TransactionManager"/> instance from the current datasource.
		/// </summary>
		/// <returns></returns>
		public override TransactionManager CreateTransaction()
		{
			return new TransactionManager(this._connectionString);
		}
		
		/// <summary>
		/// Gets a value indicating whether to use stored procedure or not.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this repository use stored procedures; otherwise, <c>false</c>.
		/// </value>
		public bool UseStoredProcedure
		{
			get {return this._useStoredProcedure;}
			set {this._useStoredProcedure = value;}
		}
		
		 /// <summary>
        /// Gets or sets the connection string.
        /// </summary>
        /// <value>The connection string.</value>
		public string ConnectionString
		{
			get {return this._connectionString;}
			set {this._connectionString = value;}
		}
		
		/// <summary>
	    /// Gets or sets the invariant provider name listed in the DbProviderFactories machine.config section.
	    /// </summary>
	    /// <value>The name of the provider invariant.</value>
	    public string ProviderInvariantName
	    {
	        get { return this._providerInvariantName; }
	        set { this._providerInvariantName = value; }
	    }		
		
		///<summary>
		/// Indicates if the current <see cref="NetTiersProvider"/> implementation supports Transacton.
		///</summary>
		public override bool IsTransactionSupported
		{
			get
			{
				return true;
			}
		}

		
		#region "ActivityProvider"
			
		private SqlActivityProvider innerSqlActivityProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Activity"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override ActivityProviderBase ActivityProvider
		{
			get
			{
				if (innerSqlActivityProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlActivityProvider == null)
						{
							this.innerSqlActivityProvider = new SqlActivityProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlActivityProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlActivityProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlActivityProvider SqlActivityProvider
		{
			get {return ActivityProvider as SqlActivityProvider;}
		}
		
		#endregion
		
		
		#region "SettingProvider"
			
		private SqlSettingProvider innerSqlSettingProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Setting"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override SettingProviderBase SettingProvider
		{
			get
			{
				if (innerSqlSettingProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlSettingProvider == null)
						{
							this.innerSqlSettingProvider = new SqlSettingProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlSettingProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlSettingProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlSettingProvider SqlSettingProvider
		{
			get {return SettingProvider as SqlSettingProvider;}
		}
		
		#endregion
		
		
		#region "SlideTypeProvider"
			
		private SqlSlideTypeProvider innerSqlSlideTypeProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="SlideType"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override SlideTypeProviderBase SlideTypeProvider
		{
			get
			{
				if (innerSqlSlideTypeProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlSlideTypeProvider == null)
						{
							this.innerSqlSlideTypeProvider = new SqlSlideTypeProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlSlideTypeProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlSlideTypeProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlSlideTypeProvider SqlSlideTypeProvider
		{
			get {return SlideTypeProvider as SqlSlideTypeProvider;}
		}
		
		#endregion
		
		
		#region "UserAccountProvider"
			
		private SqlUserAccountProvider innerSqlUserAccountProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="UserAccount"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override UserAccountProviderBase UserAccountProvider
		{
			get
			{
				if (innerSqlUserAccountProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlUserAccountProvider == null)
						{
							this.innerSqlUserAccountProvider = new SqlUserAccountProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlUserAccountProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlUserAccountProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlUserAccountProvider SqlUserAccountProvider
		{
			get {return UserAccountProvider as SqlUserAccountProvider;}
		}
		
		#endregion
		
		
		#region "SettingsProvider"
			
		private SqlSettingsProvider innerSqlSettingsProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Settings"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override SettingsProviderBase SettingsProvider
		{
			get
			{
				if (innerSqlSettingsProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlSettingsProvider == null)
						{
							this.innerSqlSettingsProvider = new SqlSettingsProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlSettingsProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlSettingsProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlSettingsProvider SqlSettingsProvider
		{
			get {return SettingsProvider as SqlSettingsProvider;}
		}
		
		#endregion
		
		
		#region "MessageConfigProvider"
			
		private SqlMessageConfigProvider innerSqlMessageConfigProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="MessageConfig"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override MessageConfigProviderBase MessageConfigProvider
		{
			get
			{
				if (innerSqlMessageConfigProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlMessageConfigProvider == null)
						{
							this.innerSqlMessageConfigProvider = new SqlMessageConfigProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlMessageConfigProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlMessageConfigProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlMessageConfigProvider SqlMessageConfigProvider
		{
			get {return MessageConfigProvider as SqlMessageConfigProvider;}
		}
		
		#endregion
		
		
		#region "SlideProvider"
			
		private SqlSlideProvider innerSqlSlideProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Slide"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override SlideProviderBase SlideProvider
		{
			get
			{
				if (innerSqlSlideProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlSlideProvider == null)
						{
							this.innerSqlSlideProvider = new SqlSlideProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlSlideProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlSlideProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlSlideProvider SqlSlideProvider
		{
			get {return SlideProvider as SqlSlideProvider;}
		}
		
		#endregion
		
		
		#region "MenuProvider"
			
		private SqlMenuProvider innerSqlMenuProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Menu"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override MenuProviderBase MenuProvider
		{
			get
			{
				if (innerSqlMenuProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlMenuProvider == null)
						{
							this.innerSqlMenuProvider = new SqlMenuProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlMenuProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlMenuProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlMenuProvider SqlMenuProvider
		{
			get {return MenuProvider as SqlMenuProvider;}
		}
		
		#endregion
		
		
		#region "HospitalProvider"
			
		private SqlHospitalProvider innerSqlHospitalProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Hospital"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override HospitalProviderBase HospitalProvider
		{
			get
			{
				if (innerSqlHospitalProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlHospitalProvider == null)
						{
							this.innerSqlHospitalProvider = new SqlHospitalProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlHospitalProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlHospitalProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlHospitalProvider SqlHospitalProvider
		{
			get {return HospitalProvider as SqlHospitalProvider;}
		}
		
		#endregion
		
		
		#region "AppointmentProvider"
			
		private SqlAppointmentProvider innerSqlAppointmentProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Appointment"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override AppointmentProviderBase AppointmentProvider
		{
			get
			{
				if (innerSqlAppointmentProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlAppointmentProvider == null)
						{
							this.innerSqlAppointmentProvider = new SqlAppointmentProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlAppointmentProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlAppointmentProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlAppointmentProvider SqlAppointmentProvider
		{
			get {return AppointmentProvider as SqlAppointmentProvider;}
		}
		
		#endregion
		
		
		#region "ArticleProvider"
			
		private SqlArticleProvider innerSqlArticleProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Article"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override ArticleProviderBase ArticleProvider
		{
			get
			{
				if (innerSqlArticleProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlArticleProvider == null)
						{
							this.innerSqlArticleProvider = new SqlArticleProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlArticleProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlArticleProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlArticleProvider SqlArticleProvider
		{
			get {return ArticleProvider as SqlArticleProvider;}
		}
		
		#endregion
		
		
		#region "ContactProvider"
			
		private SqlContactProvider innerSqlContactProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Contact"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override ContactProviderBase ContactProvider
		{
			get
			{
				if (innerSqlContactProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlContactProvider == null)
						{
							this.innerSqlContactProvider = new SqlContactProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlContactProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlContactProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlContactProvider SqlContactProvider
		{
			get {return ContactProvider as SqlContactProvider;}
		}
		
		#endregion
		
		
		#region "FaqProvider"
			
		private SqlFaqProvider innerSqlFaqProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Faq"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override FaqProviderBase FaqProvider
		{
			get
			{
				if (innerSqlFaqProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlFaqProvider == null)
						{
							this.innerSqlFaqProvider = new SqlFaqProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlFaqProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlFaqProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlFaqProvider SqlFaqProvider
		{
			get {return FaqProvider as SqlFaqProvider;}
		}
		
		#endregion
		
		
		#region "FileProvider"
			
		private SqlFileProvider innerSqlFileProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="File"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override FileProviderBase FileProvider
		{
			get
			{
				if (innerSqlFileProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlFileProvider == null)
						{
							this.innerSqlFileProvider = new SqlFileProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlFileProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlFileProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlFileProvider SqlFileProvider
		{
			get {return FileProvider as SqlFileProvider;}
		}
		
		#endregion
		
		
		#region "UserTypeProvider"
			
		private SqlUserTypeProvider innerSqlUserTypeProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="UserType"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override UserTypeProviderBase UserTypeProvider
		{
			get
			{
				if (innerSqlUserTypeProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlUserTypeProvider == null)
						{
							this.innerSqlUserTypeProvider = new SqlUserTypeProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlUserTypeProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlUserTypeProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlUserTypeProvider SqlUserTypeProvider
		{
			get {return UserTypeProvider as SqlUserTypeProvider;}
		}
		
		#endregion
		
		
		
		#region "General data access methods"

		#region "ExecuteNonQuery"
		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteNonQuery(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteNonQuery(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		public override void ExecuteNonQuery(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			database.ExecuteNonQuery(commandWrapper);	
			
		}

		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		public override void ExecuteNonQuery(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			database.ExecuteNonQuery(commandWrapper, transactionManager.TransactionObject);	
		}


		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteNonQuery(commandType, commandText);	
		}
		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteNonQuery(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#region "ExecuteDataReader"
		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteReader(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			Database database = transactionManager.Database;
			return database.ExecuteReader(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteReader(commandWrapper);	
		}

		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			Database database = transactionManager.Database;
			return database.ExecuteReader(commandWrapper, transactionManager.TransactionObject);	
		}


		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteReader(commandType, commandText);	
		}
		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteReader(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#region "ExecuteDataSet"
		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteDataSet(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			Database database = transactionManager.Database;
			return database.ExecuteDataSet(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteDataSet(commandWrapper);	
		}

		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			Database database = transactionManager.Database;
			return database.ExecuteDataSet(commandWrapper, transactionManager.TransactionObject);	
		}


		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteDataSet(commandType, commandText);	
		}
		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteDataSet(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#region "ExecuteScalar"
		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override object ExecuteScalar(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteScalar(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override object ExecuteScalar(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			Database database = transactionManager.Database;
			return database.ExecuteScalar(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override object ExecuteScalar(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteScalar(commandWrapper);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override object ExecuteScalar(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			Database database = transactionManager.Database;
			return database.ExecuteScalar(commandWrapper, transactionManager.TransactionObject);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override object ExecuteScalar(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteScalar(commandType, commandText);	
		}
		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override object ExecuteScalar(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteScalar(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#endregion


	}
}
